import java.util.Scanner;

class Solution {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入初始数组长度");
        int arrLength = sc.nextInt();
        int[] original = new int[arrLength];
        int count = 0;
        while (true) {
            System.out.println("请输入要插入的元素");
            int data = sc.nextInt();
            System.out.println("请输入要插入的下标");
            int index = sc.nextInt();
            if (original[index] == 0) {
                original[index] = data;
                count++;
            } else {
                System.out.println("已经赋值过了，帮您修改");
                original[index]=data;
            }
            if (count >= (arrLength * 4 / 5)) {
                int[] newArrayTwo = newArray(original, count);
                System.out.println("新数组的长度" + newArrayTwo.length);
                break;
            }
        }


    }

    private static int[] newArray(int[] original, int arrCount) {
        int newLength = original.length * 2;
        int[] newArrayOne = new int[newLength];
        for (int i = 0; i < original.length; i++) {
            newArrayOne[i] = original[i];
        }
        return newArrayOne;
    }


}
